package com.gaoyi.basemodule.baseUtil;

import android.text.TextUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateFormatUtil {

    public static String DateTimeToStr(Date date, String format) {
        //可根据需要自行截取数据显示
        if (date == null)
            return "";
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, LanguageUtils.getInstance().getCurrentLanguage());
            return simpleDateFormat.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    public static String DateTimeToStr(Date date, String format,String defaultReturn) {
        //可根据需要自行截取数据显示
        if (date == null)
            return defaultReturn;
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, LanguageUtils.getInstance().getCurrentLanguage());
            return simpleDateFormat.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return defaultReturn;
    }

    public static Date StrToDateTime(String str, String format) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, LanguageUtils.getInstance().getCurrentLanguage());
            return simpleDateFormat.parse(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
